package edu.predatorwars.shared.models;

import java.io.Serializable;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;


public class Location implements Serializable
{
	private Terrain terrain;
	private final boolean startLocation;
	private Resource resource;
	private Player player;
	
	@JsonCreator
	public Location(@JsonProperty("terrain") Terrain terrain, @JsonProperty("startLocation") Boolean startLocation)
	{
		this.terrain = terrain;
		this.startLocation = startLocation;
	}
	
	public Location(int TerrainType, boolean Traversable, boolean SightBlocked, boolean startLocation)
	{
		this.terrain = new Terrain(TerrainType, Traversable, SightBlocked);
		this.startLocation = startLocation;
	}
	
	
	/**
	 * Returns the Terrain details for this location.
	 * @return
	 */
	public Terrain getTerrain() 
	{
		return terrain;
	}
	
	/**
	 * Returns the resource at this location, null if none are here.
	 * @return
	 */
	public Resource getResource() 
	{
		return resource;
	}
	
	/**
	 * Returns the creature currently positioned at this location.
	 * @return
	 */
	public Player getPlayer() 
	{
		return player;
	}
	
	/**
	 * Sets the Resource at this location.
	 * @return
	 */
	public void setResource(Resource resource) 
	{
		this.resource = resource;
	}
	
	/**
	 * Sets the creature at this location.
	 * @return
	 */
	public void setPlayer(Player player) 
	{
		this.player = player;
	}
	
	/*
	 * Sets the terrain at this location
	 * @return
	 */
	public void setTerrain(Terrain terrain) {
		this.terrain = terrain;
	}
	
	/*
	 * Sets Terrain, resource, and player at the location to null
	 * @return
	 */
	public void nullify() {
		this.player = null;
		this.resource = null;
		this.terrain.setTerrainType(Terrain.EMPTY, false, false);
	}
	
	
	/**
	 * Returns true iff this location can be a start location.
	 * @return
	 */
	public boolean isStartLocation()
	{
		return startLocation;
	}
}
